package com.lagou.phase1.module3.work2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class WorkerTest {
    public static void main(String[] args) {
        //1.创建worker类的对象
        Worker wk1 = new Worker("凤姐", 18, 20000);
        Worker wk2 = new Worker("欧阳锋", 60, 8000);
        Worker wk3 = new Worker("刘德华", 40, 30000);

        //2.定义List集合并添加三个员工,并打印
        List<Worker> list = new ArrayList<>();
        list.add(wk1);
        list.add(wk2);
        list.add(wk3);
        System.out.println("添加进来的员工信息如下："+list);

        //3.在欧阳锋前插入一个员工，信息为：姓名："张柏芝"，年龄：35，工资3300
        list.add(1,new Worker("张柏芝",35,3300));
        System.out.println("添加新员工之后的信息如下："+list);

        //4.删除刘德华的信息
        list.remove(3);

        //5.利用for循环遍历，打印List 中所有员工的信息
        int num=list.size();
        for (int i=1;i<=num;i++) {
            System.out.println("获取到的第"+i+"个员工为："+list.get(i-1));
        }

        //6.利用迭代遍历，对List中所有的员工调用work方法
        //6.1 为List集合创建一个迭代器对象
        Iterator iterator = list.iterator();
        //6.2 用迭代器遍历所有员工并调用work方法
        for(;iterator.hasNext();) {
            Worker wk = (Worker) iterator.next();
            wk.work();
        }

        //7.为Worker类重写equals 方法，当姓名、年龄、工资全部相等时候才返回true
        //测试重写后的equals方法
        Worker wk = new Worker("张飞",18,6666);
        boolean b=wk1.equals(new Worker("zhangfei",18,6666));
        b=wk.equals(new Worker("张飞",19,6666));
        System.out.println(b);
        b=wk.equals(new Worker("张飞",18,7777));
        System.out.println(b);
        b=wk.equals(new Worker("张飞",18,6666));
        System.out.println(b);



    }
}
